package edu.nepu.flink.api.sink;

import org.apache.flink.api.common.eventtime.Watermark;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;

/**
 * @Date 2024/2/29 11:03
 * @Created by chenshuaijun
 */
public class SelfDefineSink {

    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        DataStreamSource<String> streamSource = env.socketTextStream("hadoop102", 9999);

        streamSource.addSink(new MySink());
    }

    static class MySink implements SinkFunction<String>{

        /**
         * 主要的方法，是将流中的数据发送出去
         * @param value The input record.
         * @param context Additional context about the input record.
         * @throws Exception
         */
        @Override
        public void invoke(String value, Context context) throws Exception {
            SinkFunction.super.invoke(value, context);
        }

        @Override
        public void writeWatermark(Watermark watermark) throws Exception {
            SinkFunction.super.writeWatermark(watermark);
        }

        @Override
        public void finish() throws Exception {
            SinkFunction.super.finish();
        }
    }
}
